package com.jic.point.controller;
import com.alibaba.fastjson.JSON;
import com.jic.point.model.entity.ConfBdMoneyLog;
import com.jic.point.model.entity.ConfPlatform;
import com.jic.point.model.vo.request.ConfBdMoneyLogRequest;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.github.pagehelper.PageInfo;
import java.util.List;
import com.jic.point.constant.consist.ResponseCode;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
import com.jic.point.model.vo.request.ConfPlatformLogRequest;
import com.jic.point.model.vo.response.ConfPlatformLogResponse;
import com.jic.point.model.entity.ConfPlatformLog;
import com.jic.point.service.ConfPlatformLogService;
/**
 * @Author: tzc
 * @date: 2020-10-11 17:28:32
 */
 @RestController
 @Slf4j
 @RequestMapping("/confPlatformLog")
 @Api(tags = " [平台积分流水表]控制类-PC")
public class ConfPlatformLogController {
	@Autowired
	private ConfPlatformLogService service;
	
	
     /**
      *新增记录
      * @param request 新增[平台积分流水表]请求参数
      * @return ConfPlatformLogResponse 新增[平台积分流水表]响应参数
      * author tzc
      * @date 2020-3-11 20:54:04
      */
    @ApiOperation(value = "新增[平台积分流水表]记录")
    @PostMapping("/save")
    @ResponseBody
    public RestResult<Long> save(@RequestBody ConfPlatformLogRequest request) throws Throwable {
     		ConfPlatformLog confPlatformLog = new ConfPlatformLog();
    		BeanUtils.copyProperties(request, confPlatformLog);
    	    long flag = service.save(confPlatformLog);
     return RestResult.success(flag);
    }
	
     /**
      * 新增或修改记录
      * @param request 新增或修改[平台积分流水表]请求参数
      * @return ConfPlatformLogResponse 新增或修改[平台积分流水表]响应参数
      * author tzc
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "保存或更新[平台积分流水表]")
     @PostMapping("/saveOrUpdate")
      @ResponseBody
     public RestResult<Long> saveOrUpdate(@Validated @RequestBody ConfPlatformLogRequest request) throws Throwable {
      		ConfPlatformLog confPlatformLog = new ConfPlatformLog();
		     BeanUtils.copyProperties(request, confPlatformLog);
	         long flag =   service.saveOrUpdate(confPlatformLog);
      return RestResult.success(flag);
     }
	
     /**
      * 删除记录
      * @param request 删除[平台积分流水表]请求参数
      * @return ConfPlatformLogResponse 删除[平台积分流水表]响应参数
      * author tzc
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "删除[平台积分流水表]记录")
     @PostMapping("/delete")
     @ResponseBody
     public RestResult<Long> delete(@RequestBody ConfPlatformLogRequest request) throws Throwable {
      		ConfPlatformLog confPlatformLog = new ConfPlatformLog();
	     	BeanUtils.copyProperties(request, confPlatformLog);
	         long flag = service.deleteByPrimaryKeyLogically(confPlatformLog);
      return RestResult.success(flag);
     }
	
     /**
      * 修改记录
      * @param request 修改[平台积分流水表]请求参数
      * @return ConfPlatformLogResponse 修改[平台积分流水表]响应参数
      * author tzc
      * @date 2020-3-11 20:54:04
      */
     @ApiOperation(value = "修改[平台积分流水表]记录")
     @PostMapping("/update")
     @ResponseBody
     public RestResult<Long> update(@RequestBody ConfPlatformLogRequest request) throws Throwable {
      		ConfPlatformLog confPlatformLog = new ConfPlatformLog();
	     	BeanUtils.copyProperties(request, confPlatformLog);
	         long flag = service.updateByPrimaryKeySelective(confPlatformLog);
      return RestResult.success(flag);
     }
	
     /**
      * 单表查询详情信息
      * @param request 查询[平台积分流水表]详情请求参数
      * @return ConfPlatformLogResponse 查询[平台积分流水表]详情响应参数
      * author tzc
      * @date 2020-3-11 20:54:04
      */
      @PostMapping("/getByPrimaryKey")
      @ApiOperation(value = "查询[平台积分流水表]详情")
      @ResponseBody
     public RestResult<ConfPlatformLogResponse> getByPrimaryKey(@Validated  @RequestBody ConfPlatformLogRequest request) {
     	log.info("查询详情请求参数入参，{}", JSONObject.toJSONString(request));
	     if (request!=null && request.getId()!=null) {
	      
	     	ConfPlatformLog confPlatformLog = new ConfPlatformLog();
	     	BeanUtils.copyProperties(request, confPlatformLog);
	     	ConfPlatformLog result = service.getByPrimaryKey(confPlatformLog);
		     log.info("查询详情请求参数出参，{}", JSONObject.toJSONString(result));
		     if (result == null) {
		     	return RestResult.error(ResponseCode.EXCEPTION, "记录不存在");
		     }
		     ConfPlatformLogResponse bo = new ConfPlatformLogResponse();
		     BeanUtils.copyProperties(result, bo);
	     	return RestResult.success(bo);
	     }
     	log.info("查询详情请求结束");
	     return RestResult.success(new ConfPlatformLogResponse());
     }
	
    /**
      * 分页查询
      *
      * @param request 分页查询请求参数
      * @return 分页列表
      * @throws Throwable 业务异常和系统异常
      */
     @PostMapping("/listPage")
     @ApiOperation(value = " 分页查询列表 ")
     @ResponseBody
     public RestResult<PageInfo<ConfPlatformLog>> listPage (@RequestBody ConfPlatformLogRequest request) throws Throwable {
      ConfPlatformLog param = new ConfPlatformLog();
      BeanUtils.copyProperties(request, param);
      param.setDeleteFlag(0);
     return RestResult.success(service.listPageBySelective(param, request.getPageNum(),request.getPageSize()));
     }


    /**
     * 分页查询
     *
     * @param request 分页查询请求参数
     * @return 分页列表
     * @throws Throwable 业务异常和系统异常
     */
    @PostMapping("/listPageAll")
    @ApiOperation(value = " 分页查询列表 ")
    @ResponseBody
    public RestResult<PageInfo<ConfPlatformLog>> listPageAll(@RequestBody ConfPlatformLogRequest request) throws Throwable {
        ConfPlatformLog param = new ConfPlatformLog();
        BeanUtils.copyProperties(request, param);
        param.setDeleteFlag(0);
        return RestResult.success(service.listPageAll(param, request.getPageNum(),request.getPageSize()));
    }

	
      /**
       *CONF_PLATFORM_LOG 查询列表（不分页）
       * @param  request 前端请求参数
       */
      @PostMapping("/listAll")
      @ApiOperation(value = "不分页查询 [平台积分流水表] ")
      @ResponseBody
      public RestResult<List<ConfPlatformLogResponse>>  listConfPlatformLogAllRecord(@RequestBody ConfPlatformLogRequest request) throws Throwable {
      		ConfPlatformLog param = new ConfPlatformLog();
	     	BeanUtils.copyProperties(request, param);
	     	param.setDeleteFlag(0);
	     	List<ConfPlatformLog> list = service.listAllRecord(param);
			List<ConfPlatformLogResponse> responseList = list.stream().map(temp -> {
			ConfPlatformLogResponse bo = new ConfPlatformLogResponse();
			BeanUtils.copyProperties(temp, bo);
			return bo;
			}).filter(item -> item != null).collect(Collectors.toList());
		    return RestResult.success(responseList);
      }



    /**
     *
     *
     * @description: 为平台添加虚拟预算
     * @return:
     * @author: fengrui
     * @time: 2020/12/06 17:29
     */
    @PostMapping("virtual")
    @ApiOperation(value = "虚拟预算")
    @ResponseBody
    public RestResult<Boolean> virtual(@RequestBody ConfPlatformLogRequest confBdRequest){
        ConfPlatformLog confBdMoneyLog = new ConfPlatformLog();
        BeanUtils.copyProperties(confBdRequest,confBdMoneyLog);
        confBdMoneyLog.setFile(JSON.toJSON(confBdRequest.getFile()).toString());
        Boolean bool = service.virtual(confBdMoneyLog);
        return RestResult.success(bool);
    }


    /**
     *
     *
     * @description: 实体预算
     * @return: 
     * @author: fengrui
     * @time: 2020/12/07 14:29
     */  
    @ApiOperation("实体预算")
    @PostMapping("entity")
    @ResponseBody
    public RestResult<Boolean> entity(@RequestBody ConfPlatformLogRequest confPlatformLogRequest){
//        service.entity();
        ConfPlatformLog confBdMoneyLog = new ConfPlatformLog();
        BeanUtils.copyProperties(confPlatformLogRequest,confBdMoneyLog);
        confBdMoneyLog.setFile(JSON.toJSON(confPlatformLogRequest.getFile()).toString());
        Boolean bool = service.entity(confBdMoneyLog);
        return RestResult.success(bool);
    }


 }

	
